<?php
require_once("connection.php");



         class guset{
		
    protected $fname ;
       protected   $lname ;
	 protected $address ;
	 protected $city;
	
	public function CreateOrder (){}
	public function cancelOrder (){}
	public function makeReport (){}
	public function Search (){}
	public function updateOrder (){}
	
	}
class RegistedUser extends guset  {
	private $password;
	private $phone;
	private $E_mail ;
	private $gender ;
	private $image;
	private $datee;
	private $date ;
	function register($fname,$lname,$password,$E_mail,$image,$gender,$city,$phone,$address,$Date){
	
			
			$this->fname=mysql_real_escape_string($fname);
                        $this->lname=mysql_real_escape_string($lname);
			$this->password=mysql_real_escape_string($password);
			$this->E_mail=mysql_real_escape_string($E_mail);
                        $this->address=mysql_real_escape_string($address);
                        $this->image=$image ;
                        $this->gender=$gender ;
                        $this->city=$city ;
                        $this->phone=$phone ;
                        $this->datee= $Date;
                        //$safecity=mysql_real_escape_string($city);
			$q=" INSERT INTO user SET
			    fname='".$this->fname."',
                            lname='".$this->lname."',
		        password='".($this->password)."',
		        email='".$this->E_mail."',
                         image='".$this->image."',
                         gender='".$this->gender."',
                          address='".$this->address."',
		        phone='".$this->phone."',
                        city='".$this->city."',
                      
                          year='".$this->datee."',
				signup_date = now()
                               
				" or Die('error');  
                        
                
				$r=mysql_query($q); 
				if($r){
                                    

					//echo '<h3 style="color:#606 ;">registration Done :)</h2>' ;
                                        
					}
                                        
					else{
						echo 'error' ;
						echo mysql_error();
						}
					
/*           $q= " SELECT * FROM user WHERE
		  fname='".$this->fname."' AND  
		   password='".($this->password)."'
	";
           $r=mysql_query($q);
		if (mysql_num_rows($r) > 0){
	$user = mysql_fetch_array($r);
        
		$_SESSION['userName'] =$user['fname'];
                $_SESSION['userLogged'] = 1;
               $_SESSION['adminLogged']=2;
              echo $_SESSION['userName'] ;
		}
                       
*/		
		
$this->login($fname,$password);
			} // end of register function
         
		 
		 
		 
		 
		 
		                
               
 public  function login($username,$password)
{
		$query="SELECT * FROM `user` WHERE `fname`='$username' AND `password` ='$password'  ";

		if($query_run=mysql_query($query))
		{
			$query_num_rows=mysql_num_rows($query_run);
			if($query_num_rows==0)
			{
				echo 'invalid usernmae and password';	
				}	
		 else if($query_num_rows==1)
	  	{
				
					//session flag
				 $user_flag=mysql_result($query_run,0,'flag');
				 $_SESSION['flag_user']=$user_flag;
				  //session name
				   $user_name=mysql_result($query_run,0,'fname');
				  $_SESSION['user_name']=$user_name;
				     $user_name=mysql_result($query_run,0,'fname');
				 //session password
				  $user_pass=mysql_result($query_run,0,'password');
				  $_SESSION['user_pass']=$user_pass;
                                  $user_id=mysql_result($query_run,0,'userID');
                                  $_SESSION['user_id']=$user_id;
                                  $store_id=mysql_result($query_run,0,'stID');
                                  $_SESSION['store_id']=$store_id;
				  //session login
				  //session password
				  $_SESSION['login']=1;

				  if( $_SESSION['flag_user']==0)
				  {
					 // echo "welcome ".$_SESSION['user_name'].'</br>';
					 
					  }	
				   else 
				   {
				    // echo "WELCOME OUR ADMINE </br>";
					 
					 
				   }
				   // echo'you are log in log<a href="logout.php">logout </a>';
					header('location:index1.php');
				}
		
}
}
			   
			   
			   
			   
			            
                        function LogOut(){
			session_destroy();
			header ("location: index.php");
			}	
                        
                        
                       /* function LogIn($fname , $password){
		
	$this->fname=mysql_real_escape_string($fname);
	$this->password=mysql_real_escape_string($password);
	$q= " SELECT * FROM user WHERE
		  fname='".$this->fname."' AND  
		   password='".($this->password)."'
	";
	$r=mysql_query($q);
		if (mysql_num_rows($r) > 0){
	$user = mysql_fetch_array($r);
        $_SESSION['userName'] =$user['fname'];
		$_SESSION['userLogged'] = 1;
                $_SESSION['adminLogged']=2;
		$_SESSION['userID'] = $user['id'];
		$_SESSION['userName'] =$user['name'];
		$_SESSION['userDate'] = $user['signup_date'] ;
		$_SESSION['userImage'] = $user['image'] ;
		$_SESSION['userMail'] = $user['E_mail'] ;
		$_SESSION['userCountry'] = $user['country'] ;
		$_SESSION['userGender'] = $user['gender'] ;
		}
		else{
			$_SESSION['login_error'] = "please try again !! " ;
			header ("location: index.php");
			}
			
		}
                        */
                        };
                        
                        
                        
                        
               
/*
	
		
		
		
                        
              
                        
                        
                       
	
	};*/
	
	
	


                
                



?>
